import { DD_SYSTEM } from '@/constants/api-pre';
import { request } from '@/service/request';

export type AreaTree = Api.Common.CommonRecord<{
  id: number;

  name: string;

  children: AreaTree;
}>;

export type AreaTreeList = Api.Common.PaginatingQueryRecord<AreaTree>;

export type AreaTreeSearchParams = CommonType.RecordNullable<Pick<AreaTree, 'id'> & Api.Common.CommonSearchParams>;

export function fetchAllAreaTree(params?: AreaTreeSearchParams) {
  return request<AreaTreeList>({
    url: `${DD_SYSTEM}/area/tree`,
    method: 'get',
    params
  });
}

export function fetchAllProvList() {
  return request<AreaTree[]>({
    url: `${DD_SYSTEM}/area/prov/options`,
    method: 'get'
  });
}

export function fetchAreaByIp(ip: string) {
  return request<string>({
    url: `${DD_SYSTEM}/area/fetch-by-ip`,
    method: 'get',
    params: { ip }
  });
}
